package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.Account;
import com.wsg.lightaccounting.Model.AccountManager;
import com.wsg.lightaccounting.Model.CashCard;
import com.wsg.lightaccounting.Model.CreditCard;
import com.wsg.lightaccounting.Model.Customized;
import com.wsg.lightaccounting.Model.NetworkPayment;
import com.wsg.lightaccounting.R;

import java.util.List;

/**
 * Created by dell-pc on 2016/11/19.
 */

public class AccountListAdapter extends BaseAdapter{
    private Context context;
    private List<Account> accounts;
    private List<NetworkPayment> networkPayments;
    private List<Customized> customizeds;
    private List<CashCard> cashCards;
    private List<CreditCard> creditCards;

    public AccountListAdapter(Context context){
        this.context = context;
        accounts = AccountManager.accounts;
        networkPayments = AccountManager.networkPayments;
        customizeds = AccountManager.customizeds;
        cashCards = AccountManager.cashCards;
        creditCards = AccountManager.creditCards;
    }
    @Override
    public int getCount() {
        return accounts.size();
    }

    @Override
    public Object getItem(int position) {
        return accounts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return accounts.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        LayoutInflater inflater =  LayoutInflater.from(context);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.account_book_layout, null);
            textView = (TextView) convertView.findViewById(R.id.account_book_name);
            convertView.setTag(textView);
        }
        else{
            textView =(TextView) convertView.getTag();
        }
            Account account = accounts.get(position);
            AccountManager.setAccountColor(context,textView,account.getColor());
            AccountManager.setAccountName(textView,account);
        return convertView;
    }
}
